extends "../longfeng-1/longfeng-1.gd"

func _extInit():
	._extInit()
	lv = 2
	addSkill("<唯一>战斗开始时在自己同行对称位置召唤一个强大的<龙卷风>(←点击可查看说明)", "龙卷风")

var eff = null
var effCell = null
var inCells = []
func _onBattleStart():
	._onBattleStart()
	for i in getAllChas(2):
		if i.has_method("initWind") and i != self and i.rndId > rndId:
			return
	initWind()

func initWind():
	effCell = Vector2(9 - cell.x, cell.y)
	getInCell()
	eff = sys.newEff("animEff", sys.main.map.map_to_world(effCell))
	eff.setImgs(sys.getBasePath() + "/eff/jianRenFengBao", 5, true)
	eff.scale *= 6
	eff.normalSpr.position = Vector2(0, -10)
var p2 = 1
func _upS():
	._upS()
	if effCell == null:return
	var cha = masCha.matCha(effCell)
	if cha != null and cha.team != team:
		azurHurtChara(cha, att.atk * 1, sys.HurtType.WEAPON, sys.AtkType.SKILL, "龙卷风", false, p2)
		castBuff(cha, buff.b_xuanYun.new(1))

	var inChas = []	
	for i in getCellChas(effCell, 2, 1):
		azurHurtChara(i, att.atk * 0.5, sys.HurtType.WEAPON, sys.AtkType.SKILL, "龙卷风", false, p2)
		inChas.append(i)
		
	if lv > 2:
		for i in getCellChas(effCell, 5, 1):
			if inChas.has(i):continue
			for j in inCells:
				if matCha(j) == null:
					i.setCell(j)
					castBuff(i, buff.b_xuanYun.new(1))
					break
	
func getInCell():
	inCells.clear()
	for i in utils.getAllCells(2):
		if cellRan(effCell, i) <= 2:
			inCells.append(i)
	inCells.sort_custom(self, "sort")

func sort(a, b):
	return cellRan(a, effCell) < cellRan(b, effCell)
	
func _onBattleEnd():
	._onBattleEnd()
	if is_instance_valid(eff):
		eff.queue_free()
	effCell = null
	inCells.clear()
